class Observer {
    constructor(data) {
        this.observer(data);
    }
    observer(data) {
        if (!data || typeof data !== "object") {
            return;
        }
        Object.keys(data).forEach((key) => {
            this.defineReactive(data, key, data[key]);
        });
    }
    defineReactive(data, key, value) {
        let self = this;
        let dep = new Dep();
        Object.defineProperty(data, key, {
            get: function get() {
                Dep.target && dep.addSub(Dep.target);
                return value;
            },
            set: function set(newValue) {
                if (newValue !== value) {
                    self.observer(newValue);
                    value = newValue;
                    dep.notify();
                }
            }
        });
    }
}